package A1_二叉树;

public class LC_530二叉搜索树最小绝对差 {
    public static class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(){}
        TreeNode(int val){
            this.val=val;
        }
        TreeNode(int val,TreeNode left,TreeNode right){
            this.val=val;
            this.left=left;
            this.right=right;
        }
    }

    int result=Integer.MAX_VALUE;
    TreeNode pre=null;
    public int getMinimumDifference(TreeNode root) {
        traversal(root);
        return result;
    }
    public  void traversal(TreeNode cur){
        if(cur==null)
            return;
        traversal(cur.left);
        if(pre!=null)
            result=Math.min(result,cur.val-pre.val);
        pre=cur;
        traversal(cur.right);
    }

}
